<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">计划任务名称</label>
        <div class="layui-input-block">
            <input type="text" name="subject" lay-verify="required" lay-reqtext="计划任务名称不能为空" placeholder="名称" value="{$detail['subject']}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">执行时间</label>
        <div class="layui-inline">
            <select name="loop_type" lay-verify="required" lay-filter="loop_type">
                <option value="month"{if $detail.loop_type == 'month'}selected{/if}>每月</option>
                <option value="week" {if $detail.loop_type == 'week'}selected{/if}>每周</option>
                <option value="day" {if $detail.loop_type == 'day'}selected{/if}>每日</option>
                <option value="hour" {if $detail.loop_type == 'hour'}selected{/if}>每小时</option>
                <option value="now" {if $detail.loop_type == 'now'}selected{/if}>每隔</option>
            </select>
        </div>
        <div class="layui-inline month loop_data">
            <div class="layui-inline">
                <select name="loop_data[month_day]">
                    {volist name="dayOptions" id="days"}
                        <option value="{$days.value}" {if $detail.month_day == $days.value}selected{/if}>{$days.text}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-inline">
                <select name="loop_data[month_hour]">
                    {volist name="hoursOptions" id="hours"}
                        <option value="{$hours.value}" {if $detail.month_hour == $hours.value}selected{/if}>{$hours.text}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-inline week loop_data">
            <div class="layui-inline">
                <select name="loop_data[week_day]">
                    <option value="1" {if $detail.week_day == '1'}selected{/if}>周一</option>
                    <option value="2" {if $detail.week_day == '2'}selected{/if}>周二</option>
                    <option value="3" {if $detail.week_day == '3'}selected{/if}>周三</option>
                    <option value="4" {if $detail.week_day == '4'}selected{/if}>周四</option>
                    <option value="5" {if $detail.week_day == '5'}selected{/if}>周五</option>
                    <option value="6" {if $detail.week_day == '6'}selected{/if}>周六</option>
                    <option value="0" {if $detail.week_day == '0'}selected{/if}>周日</option>
                </select>
            </div>
            <div class="layui-inline">
                <select name="loop_data[week_hour]">
                    {volist name="hoursOptions" id="hours"}
                        <option value="{$hours.value}" {if $detail.week_hour == $hours.value}selected{/if}>{$hours.text}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-inline day loop_data">
            <div class="layui-inline">
                <select name="loop_data[day_hour]">
                    {volist name="hoursOptions" id="hours"}
                        <option value="{$hours.value}" {if $detail.day_hour == $hours.value}selected{/if}>{$hours.text}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-inline hour loop_data">
            <div class="layui-inline">
                <select name="loop_data[hour_minute]">
                    <option value="0" {if $detail.hour_minute == '0'}selected{/if}>00分</option>
                    <option value="10" {if $detail.hour_minute == '10'}selected{/if}>10分</option>
                    <option value="20" {if $detail.hour_minute == '20'}selected{/if}>20分</option>
                    <option value="30" {if $detail.hour_minute == '30'}selected{/if}>30分</option>
                    <option value="40" {if $detail.hour_minute == '40'}selected{/if}>40分</option>
                    <option value="50" {if $detail.hour_minute == '50'}selected{/if}>50分</option>
                </select>
            </div>
        </div>
        <div class="layui-inline now loop_data">
            <div class="layui-inline">
                <input type="text" name="loop_data[now_time]" placeholder="执行时间" value="{$detail['now_time']}" class="layui-input">
            </div>
            <div class="layui-inline">
                <select name="loop_data[now_type]">
                    <option value="minute" {if $detail['now_type'] == 'minute'} selected{/if} >分钟</option>
                    <option value="hour" {if $detail['now_type'] == 'hour'} selected{/if}>小时</option>
                    <option value="day" {if $detail['now_type'] == 'day'} selected{/if}>天</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">执行文件</label>
        <div class="layui-input-block">
            <input type="text" name="cron_file" lay-verify="required" lay-reqtext="执行文件不能为空" placeholder="执行文件" value="{$detail.cron_file}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">启用状态</label>
        <div class="layui-input-block">
            <input type="radio" name="isopen" value="1" title="启用" {if $detail.isopen == '1'}checked{/if}>
            <input type="radio" name="isopen" value="0" title="关闭" {if $detail.isopen == '0'}checked{/if}>
        </div>
    </div>
    <input type="hidden" name="cron_id" value="{$detail['cron_id']}">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/static/admin/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: "{:url('cron.Cron/edit')}",
                type: 'post',
                dataType: 'json',
                data:data.field,
                success: function (data) {
                    layer.msg(data.msg);
                    //添加成功
                    if(data['status']){
                        setTimeout(function(){
                            location.reload();
                        }, 2000)
                    }
                },
                error: function (xhr, textstatus, thrown) {
                    return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
                }
            });

            return false;
        });
        $(".loop_data").hide();
        var loopType = "{$detail.loop_type}";
        $("."+loopType).show();
        //执行时间
        form.on('select(loop_type)', function(data){
            var value = data.value;
            $(".loop_data").hide();
            $("."+value).show();
        });

    });
</script>
</body>
</html>